<?
ob_start();
session_start();
$sess_id=$_SESSION['sess_id'];
$sess_user=$_SESSION['sess_user'];
$sess_status=$_SESSION['sess_status'];
$flag = $_SESSION['sess_flag'];
if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
	$_SESSION['cur_page'] = "admin/index.php?module=location";
	header( "Location: ../login.php");exit();
}
include('../config.inc.php');
echo "<meta http-equiv='content-type' content='text/html; charset=$charset'>"; 
?>
<html>
<head>
<title><?php echo $title;?></title>
</head>
<script language="JavaScript">
	   
function GetXmlHttp(){
	var HttPRequest = false;
	if(window.XMLHttpRequest) { // Mozilla, Safari,...
		HttPRequest = new XMLHttpRequest();
		if (HttPRequest.overrideMimeType) {
			HttPRequest.overrideMimeType('text/html');
		}
		return HttPRequest;
	}else if(window.ActiveXObject) { // IE
		try {
			HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
			 return HttPRequest;
	} 	  
	if (!HttPRequest) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
}
function addlocation(type,lname,page) {
		//alert(type);
		//alert(lname);
		//alert(page);
		HttPRequest = GetXmlHttp();
		var url = 'updatesql.php';
		var pmeters = "type="+type+"&lname="+lname+"&page="+page;
		HttPRequest.onreadystatechange = function(){
			if(HttPRequest.readyState == 3){document.getElementById("stlocation").innerHTML = "Now is Loading...";}
			if(HttPRequest.readyState == 4){
				document.getElementById("stlocation").innerHTML = HttPRequest.responseText;
				showLocation();
				document.getElementById("locaform").innerHTML = "";
			}		
		};
		HttPRequest.open('POST',url,true);
		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
}
function showLocation(){
	   	var page ='location';
	   	HttPRequest = GetXmlHttp();
		var url = 'updatesql.php';
		var pmeters = "page="+page;
		HttPRequest.onreadystatechange = function(){
			if(HttPRequest.readyState == 3){document.getElementById("locationform").innerHTML = "Now is Loading...";}
			if(HttPRequest.readyState == 4){
				document.getElementById("locationform").innerHTML = HttPRequest.responseText;
			}	
		};
		HttPRequest.open('POST',url,true);
		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
}
function updateloca(type,location,page){
   	HttPRequest = GetXmlHttp();
	var url = 'updatesql.php';
	var pmeters = "type="+type+"&location="+location+"&page="+page;
	HttPRequest.onreadystatechange = function(){
		if(HttPRequest.readyState == 3){document.getElementById("stlocation").innerHTML = "Now is Loading...";}
		if(HttPRequest.readyState == 4){
			document.getElementById("stlocation").innerHTML = HttPRequest.responseText;
			//showLocation();
		}	
	};
	HttPRequest.open('POST',url,true);
	HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	HttPRequest.setRequestHeader("Content-length", pmeters.length);
	HttPRequest.setRequestHeader("Connection", "close");
	HttPRequest.send(pmeters);
}
function delloca(type,page){
   	HttPRequest = GetXmlHttp();
	var url = 'updatesql.php';
	var pmeters = "page="+page+"&type="+type;
	HttPRequest.onreadystatechange = function(){
		if(HttPRequest.readyState == 3){document.getElementById("stlocation").innerHTML = "Now is Loading...";}
		if(HttPRequest.readyState == 4){
			document.getElementById("stlocation").innerHTML = HttPRequest.responseText;
			showLocation();
		}	
	};
	HttPRequest.open('POST',url,true);
	HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	HttPRequest.setRequestHeader("Content-length", pmeters.length);
	HttPRequest.setRequestHeader("Connection", "close");
	HttPRequest.send(pmeters);
	
}
function genformloca(){

	document.getElementById("locaform").innerHTML = "<input name='lid' type='text' id='lid'> <input name='lname' type='text' id='lname' size='10'> <input name='addf' type='button' id='addf' value='บันทึกข้อมูล' onClick=\"javascript:addlocation(document.getElementById('lid').value,document.getElementById('lname').value,'addlocation');\">";

}
</script>
<body onLoad="JavaScript:showLocation();">
<div ><input name="addloca" type="button" value="เพิ่ม" onClick="javascript:genformloca();"></div>
<div id='stlocation'></div>
<div id='locaform'></div>
<div id='locationform'></div>
</body>
</html>
